1
|
|
|
|
2
|
|
|
$(document).ready(function(){ |
3
|
|
|
$('#documenter_nav').tendina({activeMenu: '.current'}); |
4
|
|
|
|
5
|
|
|
var hash = window.location.hash; |
6
|
|
|
var a = $('a[href="' + hash + '"]', '#scroll'); |
7
|
|
|
if (a.length) { |
8
|
|
|
$('a[href="'+ hash +'"]', '#scroll')[0].click(); |
9
|
|
|
} else { |
10
|
|
|
window.location.hash = $($("a[href^='#']")[0]).attr('href'); |
11
|
|
|
} |
12
|
|
|
$('section.method').each(function() { |
13
|
|
|
var waypoint = new Waypoint({ |
|
|
|
|
14
|
|
|
element : this, |
15
|
|
|
handler : function() { |
16
|
|
|
var id = this.element.attributes['id'].nodeValue; |
17
|
|
|
// |
18
|
|
|
$('a', '#scroll').removeClass('current'); |
19
|
|
|
$('ul', '#scroll').removeClass('open'); |
20
|
|
|
var a = $('a[href="#' + id + '"]', '#scroll'); |
21
|
|
|
a.addClass('current'); |
22
|
|
|
|
23
|
|
|
var ul = a.closest('ul'); |
24
|
|
|
if (ul.length) { |
25
|
|
|
openUl(ul); |
26
|
|
|
} |
27
|
|
|
if (a.next().is('ul')) { |
28
|
|
|
a.next().addClass('open'); |
29
|
|
|
} |
30
|
|
|
history.replaceState(null, null, document.location.pathname + '#' + id); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
}) |
33
|
|
|
}); |
34
|
|
|
$("a[href^='#']").on('click', function() { |
35
|
|
|
var a = this; |
36
|
|
|
console.log($(a).attr('href').replace('.', '\\.').replace(':', '\\:')); |
|
|
|
|
37
|
|
|
$('html, body').animate({ |
38
|
|
|
scrollTop: $($(a).attr('href').replace(new RegExp(/\./, 'g'), '\\.').replace(new RegExp(/\:/, 'g'), '\\:')).offset().top |
39
|
|
|
}); |
40
|
|
|
return false; |
41
|
|
|
}); |
42
|
|
|
}); |
43
|
|
|
|
44
|
|
|
function openUl(ul) |
45
|
|
|
{ |
46
|
|
|
ul.addClass('open'); |
47
|
|
|
var ul = ul.parent().closest('ul'); |
48
|
|
|
if (ul.length) { |
49
|
|
|
openUl(ul); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
function sendRequest(form) |
54
|
|
|
{ |
55
|
|
|
$('#toggle-lang-response').trigger('click'); |
56
|
|
|
|
57
|
|
|
var $form = $(form); |
58
|
|
|
var $section = $form.closest('section'); |
59
|
|
|
|
60
|
|
|
var $btn = $form.find('button[type="submit"]'); |
61
|
|
|
$btn.html($('#preloader-template').html()).attr('disabled', true); |
62
|
|
|
|
63
|
|
|
var headers = {}; |
64
|
|
|
$section.find('.headers-form .form-group').not('.except').each(function(key, element) { |
65
|
|
|
var $el = $(element); |
66
|
|
|
if ($el.find('.req-header-active').is(':checked')) { |
67
|
|
|
var header = $el.find('.req-header').val(); |
68
|
|
|
headers[header] = $el.find('.req-header-value').val(); |
69
|
|
|
} |
70
|
|
|
}); |
71
|
|
|
|
72
|
|
|
$.ajax({ |
73
|
|
|
url : $section.find('.action-url').val(), |
74
|
|
|
headers: headers, |
75
|
|
|
type : $form.attr('method'), |
76
|
|
|
data : $form.serializeArray(), |
77
|
|
|
success : function(response, status, xhr) { |
78
|
|
|
$btn.text('Send').attr('disabled', false); |
79
|
|
|
$section.find('.method-example-endpoint code.response-content').jsonViewer(response); |
80
|
|
|
$section.find('.method-example-endpoint code.response-headers').text(xhr.getAllResponseHeaders()); |
81
|
|
|
}, |
82
|
|
|
error : function(xhr) { |
83
|
|
|
$btn.text('Send').attr('disabled', false); |
84
|
|
|
var content = xhr.responseText; |
85
|
|
|
if (xhr.statusText && !content) { |
86
|
|
|
$.notify({ |
87
|
|
|
message: xhr.statusText |
88
|
|
|
},{ |
89
|
|
|
type: 'danger' |
90
|
|
|
}); |
91
|
|
|
} |
92
|
|
|
if (IsJsonString(content)) { |
93
|
|
|
$section.find('.method-example-endpoint code.response-content').jsonViewer(content); |
94
|
|
|
return; |
95
|
|
|
} |
96
|
|
|
var $frame = $('<iframe class="supa" style="width:100%; height:350px;">'); |
97
|
|
|
$section.find('.method-example-endpoint code.response-content').html($frame); |
98
|
|
|
setTimeout(function() { |
99
|
|
|
var doc = $frame[0].contentWindow.document; |
100
|
|
|
var $body = $('body', doc); |
101
|
|
|
$body.html(content); |
102
|
|
|
}, 1); |
103
|
|
|
|
104
|
|
|
$section.find('.method-example-endpoint code.response-headers').text(xhr.getAllResponseHeaders()); |
105
|
|
|
} |
106
|
|
|
}); |
107
|
|
|
|
108
|
|
|
return false; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
function IsJsonString(str) { |
112
|
|
|
try { |
113
|
|
|
JSON.parse(str); |
114
|
|
|
} catch (e) { |
115
|
|
|
return false; |
116
|
|
|
} |
117
|
|
|
return true; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
function changeApiUrl(input) |
121
|
|
|
{ |
122
|
|
|
var $input = $(input); |
123
|
|
|
var $form = $input.closest('form'); |
124
|
|
|
var $urlInput = $form.find('.action-url'); |
125
|
|
|
var original = $urlInput.data('original'); |
126
|
|
|
|
127
|
|
|
$form.find('input').not('.action-url').each(function(key, input) { |
128
|
|
|
if (!input.value) { |
129
|
|
|
return; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
var regexp = new RegExp('{'+ input.name +'}', "g"); |
133
|
|
|
original = original.replace(regexp, input.value); |
134
|
|
|
}); |
135
|
|
|
|
136
|
|
|
$urlInput.val(original); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
function changeTab(ident) |
140
|
|
|
{ |
141
|
|
|
$('.method-tab').hide(); |
142
|
|
|
$('.method-tab.'+ ident).show(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|